﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Create.Master" Inherits="System.Web.Mvc.ViewPage<Langben.DAL.ts_billin>" %>

<%@ Import Namespace="Common" %>
<%@ Import Namespace="Models" %>
<asp:Content ID="Content3" ContentPlaceHolderID="CurentPlace" runat="server">
创建 损溢单
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <fieldset>
        <legend>
             <input class="a2 f2" type="button"  value="创建" onclick="save()"/>
            <input class="a2 f2" type="button" onclick="BackList('ts_billin/IndexSY')" value="返回" />
        </legend>
        <div class="bigdiv">
             <%: Html.HiddenFor(model => model.GoodsDetail)%> 
             <%: Html.HiddenFor(model => model.c_type) %>
             <%: Html.HiddenFor(model => model.i_sign)%>
             <%: Html.HiddenFor(model => model.c_audi)%>
             <%: Html.HiddenFor(model => model.c_clerk)%>
             <%: Html.HiddenFor(model => model.i_no)%>
             <input type="hidden" id="tbPerson" value="<%: Html.Encode(ViewData["person"])%>" />

              <fieldset style="width:850px"> 
             <table style="width:100%">
                <tr><td> <%: Html.LabelFor(model => model.i_no) %>：</td>
                <td><input type="text" id="tbi_no" value="<%: Html.Encode(ViewData["DH"])%>" /></td>
            <td> <%: Html.LabelFor(model => model.c_orgno) %>：</td>
                <td><%: Html.EditorFor(model => model.c_orgno) %>
            <%: Html.ValidationMessageFor(model => model.c_orgno) %></td>
            <td><%: Html.LabelFor(model => model.dt_dt) %>：</td>
            <td> <%: Html.TextBox("dt_dt", ((Model != null && Model.dt_dt != null) ? Model.dt_dt.ToString().AsDateTime().ToString("yyyy-MM-dd") : ""), new { style = "width: 214px;", @class="easyui-datebox" })%>
            <%: Html.ValidationMessageFor(model => model.dt_dt) %></td>
                </tr>
                <tr><td><%: Html.LabelFor(model => model.c_id) %>：</td>
                <td colspan="3"> <%=Html.DropDownListFor(model => model.c_id, Models.SysFieldModels.GetVendorInf(), "请选择")%></td>
                <td><%: Html.LabelFor(model => model.c_base) %>：</td>
                <td> <%=Html.DropDownListFor(model => model.c_base, Models.SysFieldModels.GetBaseInf(), "请选择")%>
                <%: Html.ValidationMessageFor(model => model.c_base) %></td></tr>
                <tr><td> <%: Html.LabelFor(model => model.c_agency) %>：</td>
                <td> <%: Html.EditorFor(model => model.c_agency) %>
                <%: Html.ValidationMessageFor(model => model.c_agency) %></td>
                <td><%: Html.LabelFor(model => model.c_keeper) %>：</td>
                <td> <%: Html.EditorFor(model => model.c_keeper) %>
                <%: Html.ValidationMessageFor(model => model.c_keeper) %></td>
                <td><%: Html.LabelFor(model => model.c_clerk) %>：</td>
                <td><input type="text" id="tbc_clerk" /></td></tr>
                <tr><td> <%: Html.LabelFor(model => model.c_comment) %>：</td>
                <td><%: Html.EditorFor(model => model.c_comment) %>
                <%: Html.ValidationMessageFor(model => model.c_comment) %></td>
                <td> <%: Html.LabelFor(model => model.c_audi) %>：</td>
                <td colspan="3"> <input type="text" id="tbc_audi" /></td></tr>
                </table>  
                 </fieldset>
                 <div style="float:left;"> 
                 <div style="width:880px; height:350px"> 
                  <table id="flexigridData">
                  </table>

                 </div>  
              </div>
        </div>
    </fieldset>
    
    <div id="divQuery" title="物品目录" class="easyui-dialog" closed="true" modal="false"
        iconcls="icon-search" style=" width:850px;">
    <table id="flexigridGoodsData">
   
    </table>
    </div>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
 <script type="text/javascript">

     $(function () {
         DoGrid();

         $('#i_sign').val("已登账");
         $('#i_no').val($('#tbi_no').val());
         $('#c_audi').val($('#tbPerson').val());

         $('#tbc_clerk').val($('#tbPerson').val());
         $('#tbc_clerk').attr("disabled", true);
         $('#tbc_audi').val($('#tbPerson').val());
         $('#tbc_audi').attr("disabled", true);
         $('#tbi_no').attr("disabled", true);
         $('#flexigridGoodsData').datagrid({
             // title: '物品目录', //列表的标题
             iconCls: 'icon-site',
             width: 'auto',
             height: 'auto',
             nowrap: false,
             striped: true,
             singleSelect: true,
             collapsible: true,
             url: '../ts_goods/GetData', //获取数据的url
             sortName: 'Id',
             sortOrder: 'desc',
             idField: 'Id',

             toolbar: [
                     {
                         text: '选择',
                         iconCls: 'icon-ok',
                         handler: function () {
                             return flexiSelect();
                         }
                     }],
             columns: [[
                      { field: 'i_sign', title: '状态', width: 60 }
                	, { field: 'c_code', title: '编号', width: 80 }
				 	, { field: 'c_desc', title: '物品', width: 80 }
					, { field: 'c_model', title: '规格', width: 80 }
					, { field: 'c_unit', title: '单位', width: 80 }
					, { field: 'c_class', title: '类别', width: 80 }
					, { field: 'c_class1', title: '大类别', width: 52, hidden: true }
					, { field: 'f_pricelast', title: '最后进价', width: 52, hidden: true }
					, { field: 'f_upper', title: '库存上限', width: 60 }
					, { field: 'f_lower', title: '库存下限', width: 60 }
					, { field: 'c_py', title: '拼音', width: 52, hidden: true }
					, { field: 'c_comment', title: '备注', width: 52, hidden: true }
					, { field: 'c_vendor', title: '主供应商', width: 90 }
					, { field: 'c_base', title: '专用仓库', width: 90 }
                ]],
             pagination: true,
             rownumbers: true

         });
     });



     function save() {
         var rows = $('#flexigridData').datagrid('getRows');
         var count = 0;
         var allrow = "";
         for (var i = 0; i < rows.length; i++) {
             if (rows[i].Id == "" || rows[i].Id == null || rows[i].Id.toString() == "undefined") {

                 var row = JSON.stringify(rows[i]);
                 allrow = allrow + row + "^";
             }
         }

         $('#GoodsDetail').val(allrow);
         alert($('#GoodsDetail').val());
         $.ajax({
             url: this.action,
             type: "Post",
             data: $(document.forms[0]).serialize(),
             dataType: "json",
             success: function (data) {
                 if ($.messager) {
                     $.messager.defaults.ok = '继续';
                     $.messager.defaults.cancel = '返回';

                     $.messager.confirm('操作提示', data, function (r) {
                         if (!r) {
                             window.location.href = 'javascript:history.go(-1)';
                         }
                     });
                 }

             }
         });


     }



     //“选择”按钮，在其他（与此页面有关联）的页面中，此页面以弹出框的形式出现，选择页面中的数据
     function flexiSelect() {

         var rows = $('#flexigridGoodsData').datagrid('getSelections');
         if (rows.length == 0) {
             $.messager.alert('操作提示', '请选择数据!', 'warning');
             return false;
         }
         var indexs = 0;
         for (var i = 0; i < rows.length; i++) {

             indexs = i;
             $('#flexigridData').datagrid('insertRow', {
                 index: indexs,
                 row: {
                     c_code: rows[i].c_code,
                     c_desc: rows[i].c_desc,
                     c_model: rows[i].c_model,
                     c_unit: rows[i].c_unit,
                     f_price: rows[i].f_pricelast
                 }
             });
             $('#flexigridData').datagrid('selectRow', indexs);
             $('#flexigridData').datagrid('beginEdit', indexs);
         }
         $('#divQuery').dialog("close");  
     }



     function DoGrid() {
         $('#flexigridData').datagrid({
             iconCls: ' ',
             width: 'auto',
             height: 'auto',
             nowrap: false,
             striped: true,
             fit: true,
             collapsible: true,
             //url: '../tr_cdrinkdetail/GetData2', //获取数据的url
             sortName: 'Id',
             sortOrder: 'desc',
             idField: 'Id',

             toolbar: [

                   {
                       text: '创建',
                       iconCls: 'icon-add',
                       handler: function () {
                           return insert();
                       }
                   }],
             columns: [[
					  { field: 'c_code', title: '编号', width: 50 }
					, { field: 'c_desc', title: '品名', width: 120 }
					, { field: 'c_model', title: '规格', width: 205 }
                    , { field: 'c_unit', title: '单位', width: 65 }
                    , { field: 'f_quant', title: '数量', width: 80, editor: 'text' }
                    , { field: 'f_price', title: '单价', width: 80 }
                    , { field: 'f_amount', title: '金额', width: 80 }
                    , { field: 'c_comment', title: '备注', width: 40, editor: 'text' }
                    , { field: 'action', title: '操作', width: 100, align: 'center',
                        formatter: function (value, row, index) {
                            if (row.editing) {
                                var s = '<a href="#" onclick="saverow(' + index + ')">保存</a> ';
                                var c = '<a href="#" onclick="cancelrow(' + index + ')">取消</a>';
                                return s + c;
                            } else {
                                var e = '<a href="#" onclick="editrow(' + index + ')">编辑</a> ';
                                var d = '<a href="#" onclick="deleterow(' + index + ')">删除</a>';
                                return e + d;
                            }
                        }
                    }
                ]],
             onBeforeEdit: function (index, row) {
                 row.editing = true;
                 updateActions();
             },
             onAfterEdit: function (index, row) {
                 row.editing = false;
                 updateActions();
             },
             onCancelEdit: function (index, row) {
                 row.editing = false;
                 updateActions();
             },

             pagination: true,
             rownumbers: false

         });

     }

     function updateActions() {
         var rowcount = $('#flexigridData').datagrid('getRows').length;
         for (var i = 0; i < rowcount; i++) {
             $('#flexigridData').datagrid('updateRow', {
                 index: i,
                 row: { action: '' }
             });
         }
     }

     function saverow(index) {

         $('#flexigridData').datagrid('endEdit', index);


     }


     function editrow(index) {
         $('#flexigridData').datagrid('beginEdit', index);
     }

     function deleterow(index) {
         $.messager.confirm('操作提示', '确定删除吗?', function (r) {
             if (r) {
                 $('#flexigridData').datagrid('deleteRow', index);
             }
         });
     }

     function cancelrow(index) {
         $('#flexigridData').datagrid('cancelEdit', index);
     }

     function insert() {

         $('#divQuery').dialog("open"); 
     }

         

    </script>

</asp:Content>


